package semant.first_pass;

import util.List;
import semant.Env;
import errors.ErrorEchoer;
import syntaxtree.Program;
import syntaxtree.ClassDecl;
import syntaxtree.VisitorAdapter;

final class ProgramHandler extends VisitorAdapter {

    private Env env;

    private ProgramHandler(ErrorEchoer err){
	super();
	env = new Env(err);
    }

    static Env firstPass(ErrorEchoer err, Program p){
	ProgramHandler h = new ProgramHandler(err);
	p.accept(h);
	return h.env;
    }

    public void visit(Program node){
	// classe principal
	MainClassHandler.firstPass(env, node.mainClass);
	// outras classes
	for(List<ClassDecl> cd = node.classList; cd != null; cd = cd.tail)
	    ClassDeclHandler.firstPass(env, cd.head);
    }

}
